@PACKAGE_INIT@


if (CMAKE_VERSION VERSION_LESS @CMAKE_VERSION@)
    message(FATAL_ERROR "medInria requires at least CMake version @CMAKE_VERSION@")
endif()

if (NOT medInria_FIND_COMPONENTS)
    set(medInria_NOT_FOUND_MESSAGE "The medInria package requires at least one component")
    set(medInria_FOUND False)
    return()
endif()



set(_medInria_FIND_PARTS_REQUIRED)
if (medInria_FIND_REQUIRED)
    set(_medInria_FIND_PARTS_REQUIRED REQUIRED)
endif()

set(_medInria_FIND_PARTS_QUIET)
if (medInria_FIND_QUIETLY)
    set(_medInria_FIND_PARTS_QUIET QUIET)
endif()

get_filename_component(_medInria_install_prefix "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)

set(_medInria_NOTFOUND_MESSAGE)

########################################################################################
############################ Bolc for external dependencies ############################

cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0076 NEW)

cmake_path(SET MEDINRIA_PATH         NORMALIZE "${_medInria_install_prefix}/../../medInria")
cmake_path(SET medinria_cmake        NORMALIZE "${_medInria_install_prefix}/../../cmake")
cmake_path(SET medinria_cmake_module NORMALIZE "${_medInria_install_prefix}/../../cmake/module")


set(medInria_CMAKE_DIR
  ${medinria_cmake}
  ${medinria_cmake_module}
  )

set(CMAKE_MODULE_PATH
  ${medInria_CMAKE_DIR}
  ${CMAKE_MODULE_PATH}
  )

include(list_source_files)
include(list_header_directories_to_include)
include(set_exe_install_rules)
include(set_lib_install_rules)
include(set_lib_properties_variables)
include(set_plugin_install_rules)
include(add_external_resources)

include(add_plugins)

if (NOT DEFINED ITK_ROOT AND NOT DEFINED VTK_ROOT AND NOT DEFINED dtk_ROOT AND NOT DEFINED TTK_ROOT AND NOT DEFINED RPI_ROOT AND NOT DEFINED DCMTK_ROOT)
    message("medInria attempts to set the following paths")
endif()

if (NOT DEFINED ITK_ROOT)
    cmake_path(SET ITK_ROOT NORMALIZE ${_medInria_install_prefix}/../../dependencies/ITK)
    message("ITK_ROOT ${ITK_ROOT}")
endif()

if (NOT DEFINED VTK_ROOT)
    cmake_path(SET VTK_ROOT NORMALIZE ${_medInria_install_prefix}/../../dependencies/VTK)
    message("VTK_ROOT ${VTK_ROOT}")
endif()

if (NOT DEFINED dtk_ROOT)
    cmake_path(SET dtk_ROOT NORMALIZE ${_medInria_install_prefix}/../../dependencies/dtk)
    message("dtk_ROOT ${dtk_ROOT}")
endif()

if (NOT DEFINED TTK_ROOT)
    cmake_path(SET TTK_ROOT NORMALIZE ${_medInria_install_prefix}/../../dependencies/TTK)
    message("TTK_ROOT ${TTK_ROOT}")
endif()

if (NOT DEFINED RPI_ROOT)
    cmake_path(SET RPI_ROOT NORMALIZE ${_medInria_install_prefix}/../../dependencies/RPI)
    message("RPI_ROOT ${RPI_ROOT}")
endif()

if (NOT DEFINED DCMTK_ROOT)
    cmake_path(SET DCMTK_ROOT NORMALIZE ${_medInria_install_prefix}/../../dependencies/DCMTK)
    message("DCMTK_ROOT ${DCMTK_ROOT}")
endif()

######################## End of Bolc for external dependencies #########################
########################################################################################

include(${CMAKE_CURRENT_LIST_DIR}/medInriaModuleLocation.cmake)

if(NOT ${PROJECT_NAME} STREQUAL "medInria")

    foreach(medInriaPakageDependency ${PackagesNames})
        find_package(${medInriaPakageDependency} COMPONENTS ${medInriaPakageDependencyModulesFor${medInriaPakageDependency}})
    endforeach()

    foreach(module ${medInria_FIND_COMPONENTS})
        find_package(med${module}
            ${_medInria_FIND_PARTS_QUIET}
            ${_medInria_FIND_PARTS_REQUIRED}
            PATHS ${_med_module_paths} NO_DEFAULT_PATH
        )
        if (NOT med${module}_FOUND)
            string(CONFIGURE ${_med_module_location_template} _expected_module_location @ONLY)
    
            if (medInria_FIND_REQUIRED_${module})
                set(_medInria_NOTFOUND_MESSAGE "${_medInria_NOTFOUND_MESSAGE}Failed to find medInria component \"${module}\" config file at \"${_expected_module_location}\"\n")
            elseif(NOT medInria_FIND_QUIETLY)
                message(WARNING "Failed to find medInria component \"${module}\" config file at \"${_expected_module_location}\"")
            endif()
    
            unset(_expected_module_location)
        endif()
    endforeach()
    
    if (_medInria_NOTFOUND_MESSAGE)
        set(medInria_NOTFOUND_MESSAGE "${_medInria_NOTFOUND_MESSAGE}")
        set(medInria_FOUND False)
    endif()
else()
    set(medInria_FOUND True)
    foreach(module ${medInria_FIND_COMPONENTS})
        if (NOT TARGET med${module})
            message(" Warnning: No target med${module} found")
        endif()
    endforeach()
endif()
